#pragma once
#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<assert.h>
#include<Windows.h>
using namespace std;

#define KEY_PRESS(VK) ((GetAsyncKeyState(VK)&0x1) ? 1 : 0)

void Setpos(int x, int y);


class Maze
{
public:
	Maze(int x);
	Maze();

	
	bool GetPassage(int x = 0, int y = 0);
	void Print_Passage();

	int Game();
	void Walk();
	void Nudeg();
	void screen();
	~Maze()
	{
		for (int i = 0; i < _rows; i++)
		{
			free(_pool[i]);
		}
		free(_pool);
	}
private:
	

	bool IsNodeTure(int x = 0, int y = 0);



	class Node
	{
	public:
		Node(int x = 0, int y = 0)
		{
			_x = x;
			_y = y;
		}

		int _x;
		int _y;
	};

	typedef Node TypeData;
	class Stack
	{
	public:
		Stack(int size = 4)
			:_capacity(size)
			, _size(-1)
		{
			_a = (TypeData*)malloc(sizeof(TypeData) * size);
			assert(_a);
		}

		TypeData Top()
		{
			assert(_size >= 0);
			return _a[_size];
		}

		void Pop()
		{
			assert(_size >= 0);
			_size--;
		}

		bool IsEmpity()
		{
			if (_size == -1)
				return 1;
			else
				return 0;
		}

		void Push(TypeData x);

		Stack& operator=(Stack& s);



		Stack(Stack& s)
		{
			*this = s;
		}

		~Stack()
		{
			free(_a);
			_a = nullptr;
		}

		int GetSize()
		{
			return _size;
		}
	private:


		int GetCapacity()
		{
			return _capacity;
		}

		TypeData* _a;
		int _size;
		int _capacity;
	};

	enum DIRECTION
	{
		UP=1,
		DOWN,
		LEFT,
		RIGHT
	};

	int _rows;
	int _cols;
	Node _node;
	int** _pool;
	Stack _stack;
	Stack _minstack;
	int _x;
	int _y;
	int _dir;
};



//5 5
//0 0 1 0 0
//0 0 0 0 0
//0 1 0 1 1
//0 0 0 1 1
//1 0 0 0 0
 
//5 5
//0 0 1 0 0
//0 0 1 0 0
//0 1 0 1 1
//0 0 0 1 1
//1 0 0 0 0